home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / AIAT 1.0.1 / Headers / Accessor / TWVector.h < prev    next >
Encoding:
Text File  |  1997-09-11  |  2.8 KB  |  83 lines  |  [TEXT/CWIE]

  1. // TWVector.h
  2. //    Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  3. #pragma once
  4. #ifndef TWVector_h
  5. #define TWVector_h
  6.  
  7. #pragma import on
  8.  
  9. #include "TermIndex.h"
  10.  
  11. #pragma IA_BEGIN_EXPORTS
  12.  
  13. // TWComponent: what TWVector's are made of.
  14. struct TWComponent {
  15.     TermID            termID;                // the TermID
  16.     float            weight;                // the normalized weight of the term
  17. private:
  18.     void*            operator new(size_t size);        // stack or array allocate only
  19. };
  20.  
  21. // TWVector: available from a VectorAccessor.
  22. class TWVector : public IAObject {
  23. public:
  24.                     TWVector(DocLength l);
  25.                     ~TWVector();
  26.     
  27.     float            Similarity(TWVector* other);
  28.     void            Normalize();
  29.  
  30.     TWVector*        Sum(TWVector* other);
  31.     
  32.     void            SetDocumentLength(DocLength l) {length = l;}
  33.     void             SetComponents(TWComponent* c) {components = c;}
  34.     DocLength        GetDocumentLength() const {return length;}
  35.     TWComponent*    GetComponents() const {return components;}
  36.     
  37.     bool             HasNegativeComponents() const;
  38.     IABlockSize     StoreSize() const;
  39.     TWVector*        DeepCopy() const;
  40.     void             Store( IAOutputBlock *output ) const;
  41.     TWVector*        Restore( IAInputBlock *input ) const;
  42.     
  43. // SortByTerm is the normal ordering for the vectors
  44.     void             SortByTerm();     
  45. // SortByWeight is a special ordering for the vectors to be used
  46. //    during human-output and truncation operations it sorts by size of the component
  47.     void             SortByWeight();
  48. // SortByAbsoluteWeight is a special ordering for the vectors to be used during human-output 
  49. // and truncation operations it sorts by absolute value of the component weight
  50.     void             SortByAbsoluteWeight();
  51. // Truncate removes the terms with the lowest weights until maxTerms or fewer are left
  52.     void            Truncate(uint32 maxTerms );
  53. // TruncateByAbsoluteValue removes the terms with the lowest absolute weights until maxTerms or fewer are left
  54.     void             TruncateByAbsoluteValue(uint32 maxTerms );
  55.  
  56. // This is a cluster centroid representing totalVectorCount-1 other vectors.
  57. // The parameter is a new vector to be incorporated into this (the centroid).
  58. // The new centroid is returned.
  59. // The formula: result = (n-1/n)*this + (1/n)*newVector
  60.     TWVector*         AddIntoAverage(const TWVector *newVector, 
  61.                                     uint32 totalVectorCount, bool invertSecondVector = false);
  62. // returns a NEW TWVector, does not allow negative components in vector.
  63.     TWVector*        AddWeighted(const TWVector *vector, 
  64.                                     float weightFactor1, float weightFactor2);
  65. // returns a NEW TWVector, DOES INDEED allow negative components in vector.                                    
  66.     TWVector*         AddWeightedAllowNegatives(const TWVector *vector, 
  67.                                     float weightFactor1, float weightFactor2);
  68.  
  69. //    bool            Equal(TWVector* other);
  70.  
  71. private:
  72.                     TWVector(TWVector&);
  73.     DocLength        length;                // the number of components in the vector
  74.     TWComponent*    components;            // an array of TWComponents
  75.  
  76. };
  77.  
  78. #pragma IA_END_EXPORTS
  79.  
  80. #pragma import reset
  81.  
  82. #endif
  83.